package com.shujia.day15;

public class Code04ThreadTicket {
    public static void main(String[] args) {
        Window window = new Window();

        Thread thread1 = new Thread(window, "售票员1");
        Thread thread2 = new Thread(window, "售票员2");
        Thread thread3 = new Thread(window, "售票员3");

        thread1.start();
        thread2.start();
        thread3.start();

    }
}

class Window implements Runnable {
    int ticket = 100;

    @Override
    public void run() {
        for (int i = 1; i <= 100; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (ticket > 0) {
                System.out.println(Thread.currentThread().getName()+"销售了一张票，还剩" + --ticket + "张表");
            }
        }
    }
}